package sqlServer;

import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;

import windowUnits.ProgressBarThread;

public class UpdateThread extends Thread {
	
	private AppConnection appConn;
	private ProgressBarThread pg;
	private JTree tree;
	private DefaultMutableTreeNode node;
	
	public UpdateThread(AppConnection appConn,
			 ProgressBarThread pg,
			 JTree tree,DefaultMutableTreeNode node) {
		this.appConn = appConn;
		this.pg = pg;
		this.tree = tree;
		this.node = node;
	}
	
	public void run() {
		
		appConn.updateObject(node.getUserObject());
		((BaseDataObject)node.getUserObject()).setChanged(false);
		if(((BaseDataObject)node.getUserObject()).isOrderChanged()){
			appConn.reorderItem(node);
		}
		((BaseDataObject)node.getUserObject()).setOrderChanged(false);
		tree.repaint();
		pg.stopProgress();
	}
	
}
